package com.zh.work.service.platform.virtual.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zh.work.dao.platform.virtual.VirtualWdTransHMapper;
import com.zh.work.dao.platform.virtual.VirtualWdTransMapper;
import com.zh.work.entity.virtual.VirtualRechargeTrans;
import com.zh.work.entity.virtual.VirtualRechargeTransH;
import com.zh.work.service.platform.virtual.VirtualWdTransService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * code is far away from bug with the animal protecting
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃代码无BUG！
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 *
 * @Description: 账户提现业务接口实现
 * @Author: Li.HuiNeng
 * @Create in: 2020-02-13 13:55
 * @Version: 1.0.1
 */
@Service
public class VirtualWdTransServiceImpl extends ServiceImpl<VirtualWdTransMapper, VirtualRechargeTrans> implements VirtualWdTransService {

    @Autowired
    private VirtualWdTransMapper wdTransMapper;

    @Autowired
    private VirtualWdTransHMapper wdTransHMapper;


    @Override
    public IPage<VirtualRechargeTrans> selectVirtualWdTransPages(Page<VirtualRechargeTrans> page, VirtualRechargeTrans param) {
        return this.wdTransMapper.selectPage(page, new LambdaQueryWrapper<VirtualRechargeTrans>()
                .between(ObjectUtils.allNotNull(param.getStartDate(), param.getEndDate()),
                        VirtualRechargeTrans::getAddTime, param.getStartDate(), param.getEndDate())
                .like(StringUtils.isNotEmpty(param.getMerchNo()), VirtualRechargeTrans::getMerchNo, param.getMerchNo())
                .like(StringUtils.isNotEmpty(param.getMerchName()), VirtualRechargeTrans::getMerchName, param.getMerchName())
                .eq(Objects.nonNull(param.getPayMode()), VirtualRechargeTrans::getPayMode, param.getPayMode())
                .eq(Objects.nonNull(param.getTransType()), VirtualRechargeTrans::getTransType, param.getTransType())
                .eq(Objects.nonNull(param.getChannelCode()), VirtualRechargeTrans::getChannelCode, param.getChannelCode())
                .eq(Objects.nonNull(param.getChannelMerchantNo()), VirtualRechargeTrans::getChannelMerchantNo, param.getChannelMerchantNo())
                .eq(Objects.nonNull(param.getPayType()), VirtualRechargeTrans::getPayType, param.getPayType())
                .like(StringUtils.isNotEmpty(param.getTraceNo()), VirtualRechargeTrans::getTraceNo, param.getTraceNo())
                .ge(Objects.nonNull(param.getAmtStart()), VirtualRechargeTrans::getAmount, param.getAmtStart())
                .le(Objects.nonNull(param.getAmtEnd()), VirtualRechargeTrans::getAmount, param.getAmtEnd())
                .eq(Objects.nonNull(param.getDfType()), VirtualRechargeTrans::getDfType, param.getDfType())
                .eq(Objects.nonNull(param.getPayStatus()), VirtualRechargeTrans::getPayStatus, param.getPayStatus())
                .eq(Objects.nonNull(param.getBranchNo()), VirtualRechargeTrans::getBranchNo, param.getBranchNo())
                .eq(Objects.nonNull(param.getStatus()), VirtualRechargeTrans::getStatus, param.getStatus())
                .like(StringUtils.isNotEmpty(param.getCardNo()), VirtualRechargeTrans::getCardNo, param.getCardNo())
        );
    }

    @Override
    public IPage<VirtualRechargeTransH> selectVirtualWdTransHPages(Page<VirtualRechargeTransH> page, VirtualRechargeTransH param) {
        return this.wdTransHMapper.selectPage(page, new LambdaQueryWrapper<VirtualRechargeTransH>()
                .between(ObjectUtils.allNotNull(param.getStartDate(), param.getEndDate()),
                        VirtualRechargeTransH::getAddTime, param.getStartDate(), param.getEndDate())
                .like(StringUtils.isNotEmpty(param.getMerchNo()), VirtualRechargeTransH::getMerchNo, param.getMerchNo())
                .like(StringUtils.isNotEmpty(param.getMerchName()), VirtualRechargeTransH::getMerchName, param.getMerchName())
                .eq(Objects.nonNull(param.getPayMode()), VirtualRechargeTransH::getPayMode, param.getPayMode())
                .eq(Objects.nonNull(param.getTransType()), VirtualRechargeTransH::getTransType, param.getTransType())
                .eq(Objects.nonNull(param.getChannelCode()), VirtualRechargeTransH::getChannelCode, param.getChannelCode())
                .eq(Objects.nonNull(param.getChannelMerchantNo()), VirtualRechargeTransH::getChannelMerchantNo, param.getChannelMerchantNo())
                .eq(Objects.nonNull(param.getPayType()), VirtualRechargeTransH::getPayType, param.getPayType())
                .like(StringUtils.isNotEmpty(param.getTraceNo()), VirtualRechargeTransH::getTraceNo, param.getTraceNo())
                .ge(Objects.nonNull(param.getAmtStart()), VirtualRechargeTransH::getAmount, param.getAmtStart())
                .le(Objects.nonNull(param.getAmtEnd()), VirtualRechargeTransH::getAmount, param.getAmtEnd())
                .eq(Objects.nonNull(param.getDfType()), VirtualRechargeTransH::getDfType, param.getDfType())
                .eq(Objects.nonNull(param.getPayStatus()), VirtualRechargeTransH::getPayStatus, param.getPayStatus())
                .eq(Objects.nonNull(param.getBranchNo()), VirtualRechargeTransH::getBranchNo, param.getBranchNo())
                .eq(Objects.nonNull(param.getStatus()), VirtualRechargeTransH::getStatus, param.getStatus())
                .like(StringUtils.isNotEmpty(param.getCardNo()), VirtualRechargeTransH::getCardNo, param.getCardNo())
        );
    }


    @Override
    public int putModVirtualRateTypeById(VirtualRechargeTrans virtualRechargeTrans) {
        return this.wdTransMapper.updateById(virtualRechargeTrans);
    }
}
